{
    title:  'Database Migrations',
    crumbs: [
        { "User's Guide": 'index.html' },
    ],
}
            <h1>Database Migrations</h1>
           
            <a id="migrations"></a>
            <p>Database migrations are mini programs that modify the database schema or content. You can create database
            migrations via the <em>esp generate migration</em> command. This command generates a migration for a
            specific database table by creating or removing columns. To generate a migration:</p>

            <code class="inverted">$ <b>esp generate migration description table [field:type ...]</b></code>

            <p>This will create a migration script under the <em>migrations</em> directory. Migration script filenames are
            time stamped and use the supplied description argument as part of the filename for the migration script 
            (so keep it short and sweet and don't use spaces!).</p>

            <p>For each specified <em>field:type</em> pair, <em>esp</em> will generate code to add a column in the migration
            script. If the --reverse switch is specified, then code to remove a column will be generated. To change the 
            type or name of a column, remove then re-add the column. </p>
            
            <a id="runMigrations"></a>
            <h2>Running Migrations</h2>
            <p>Migration scripts can be run via the <em>esp migrate</em> command. Without other parameters, the
            command will run all migrations that have not yet been applied to the database. You can also use
            <em>esp migrate forward</em> to apply the next unapplied migration. Similarly, <em>esp migrate
            backward</em> will reverse the last applied migration. You can also use <em>esp migrate NNN</em> to
            migrate forward or backward to a specific migration. NNN is the migration sequence number which is the
            number at the start of the migration script file name.</p>

            <p>Migrations are often under-used. They are much more important than most people realize. Being able
            to effectively create and manage database test data greatly simplifies this aspect of 
            development and testing.</p>
            
            
